package org.suwenqian.airoleplayingchatbackend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.suwenqian.airoleplayingchatbackend.common.result.Result;
import org.suwenqian.airoleplayingchatbackend.common.web.Results;
import org.suwenqian.airoleplayingchatbackend.dao.dto.req.RoleInsertReqDTO;
import org.suwenqian.airoleplayingchatbackend.dao.dto.req.RoleListReqDTO;
import org.suwenqian.airoleplayingchatbackend.dao.dto.resp.RoleListRespDTO;
import org.suwenqian.airoleplayingchatbackend.service.RoleService;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ai-role-play/role")
public class RoleController {

    private final RoleService roleService;

    /**
     * 新增或者修改角色
     * @param requestParm 请求参数
     * @return 空值
     */
    @PostMapping("/addOrUpdateRole")
    public Result<Void> addOrUpdateRole(@RequestBody RoleInsertReqDTO requestParm) {
        roleService.addOrUpdateRole(requestParm);
        return Results.success();
    }

    /**
     * 删除角色
     * @param id 角色id
     * @return 空值
     */
    @PostMapping("/deleteRole")
    public Result<Void> deleteRole(@RequestParam String id) {
        roleService.deleteRole(id);
        return Results.success();
    }

    /**
     * 获取角色列表
     * @param requestParm 用户ID, 当前页码, 每页数量
     * @return 角色列表
     */
    @GetMapping("/queryRoleList")
    public Result<IPage<RoleListRespDTO>> queryRoleList(@RequestBody RoleListReqDTO requestParm) {
        return Results.success(roleService.queryRoleList(requestParm));
    }

    /**
     * 搜索角色
     * @param requestParm 用户搜索关键词
     * @return 角色列表
     */
    @GetMapping("/searchRoleList")
    public Result<IPage<RoleListRespDTO>> searchRoleList(@RequestParam String requestParm) {
        return Results.success(roleService.searchRoleList(requestParm));
    }

}
